package com.person.leetcode.editor.cn;

import java.util.concurrent.locks.ReentrantLock;

public class Demo {
    public Object a = new Object();
    public static synchronized void  testStatic() throws InterruptedException {

        System.out.println("testStatic");
        Thread.sleep(5000);
    }
    public synchronized void  testInstance() throws InterruptedException {

        System.out.println("testInstance");
        Thread.sleep(5000);
    }
    public void testThis() throws InterruptedException {
        synchronized (a){
            System.out.println("this");
            Thread.sleep(5000);
        }
    }

    public static void main(String[] args) throws InterruptedException {
        Demo demo = new Demo();
        new Thread(()->{
            try {
                System.out.println("thread1");
                demo.testThis();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }).start();
        new Thread(()->{
            System.out.println("a start");
            System.out.println(demo.a);
            System.out.println("a end");
        }).start();
        new Thread(()->{
            try {
                System.out.println("thread2");

//                demo.testInstance();
                Demo.testStatic();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }).start();

        Thread.sleep(60*1000);

        ReentrantLock lock = new ReentrantLock();
        lock.lock();
        lock.tryLock();
        lock.unlock();
    }
}
